import time

SECONDS_PER_DAY = 24 * 60 * 60
# exec task every 2:00 AM
(nHour, nMinute, nSecond) = (23, 30, 0)

def scheduleWork():
    import os
    os.system("regular_run.bat")

def checkTime():
    from datetime import datetime,timedelta
    curTime = datetime.now()
    destTodayTime = curTime.replace(hour=nHour, minute=nMinute, second=nSecond, microsecond=0)
    desTommorrowTime = destTodayTime
    if destTodayTime < curTime:
		desTommorrowTime = destTodayTime + timedelta(days=1)
    print "Next exec time: " + desTommorrowTime.strftime("%Y %m %d %H:%M:%S")
    skipSeconds = desTommorrowTime - curTime
    print "Must sleep %d seconds" % skipSeconds.total_seconds()
    return skipSeconds.total_seconds()

if __name__ == "__main__":
    while True:
        tick = checkTime()
        time.sleep((float)(tick))
        scheduleWork()